/*
 * @Author: your name
 * @Date: 2021-03-30 12:52:54
 * @LastEditTime: 2021-03-30 13:18:21
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \my-app-koa\validation\register.js
 */
const Validator = require('validator');
const isEmpty = require("./is-empty.js")
module.exports = function validateLoginInput(data) {
  let errors = {};
  if (!Validator.isLength(data.password, { min: 8, max: 30 })) {
    errors.password = "用户名长度不能小于8并且大于30"
  }
  if (Validator.isEmpty(data.password)) {
    errors.password = "用户名不能为空"
  }
  if (Validator.isEmpty(data.email)) {
    errors.email = "邮箱不能为空"
  }
  if (!Validator.isEmail(data.email)) {
    errors.email = "邮箱不合法"
  }

  return {
    errors,
    isValid: isEmpty(errors)
  }
}
